package com.xxx.modules.sys.controller;

import com.xxx.common.utils.R;
import com.xxx.modules.sys.domain.SysTextDomain;
import com.xxx.modules.sys.domain.SysUserTextDomain;
import com.xxx.modules.sys.service.SysTextService;
import com.xxx.modules.sys.service.SysUserTextService;
import com.xxx.modules.sys.service.UserTextService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**  文章 Controller
 * Created by ChenXuefei on 2017/10/16.
 */
@RestController
@Slf4j
public class SysUserTextController {

    @Autowired
    private SysUserTextService sysUserTextService;
    @Autowired
    private SysTextService sysTextService;
    @Autowired
    UserTextService userTextService;

    @RequestMapping("sys/user/text/query")
    public R queryTextByUserId(String userId){
        log.debug("【 开始查询文章 】");
        List<SysTextDomain> sysTextDomains =  userTextService.queryText(userId);
        log.debug("【 查询文章结束 】");
        return R.ok().put("texts",sysTextDomains);
    }

    @RequestMapping("sys/user/text/queryInfo")
    public R queryTextInfoByUserId(String id){
        log.debug("【 开始查询文章 】");
        SysTextDomain sysTextDomain =  userTextService.queryTextInfoByTextId(id);
        log.debug("【 查询文章结束 】");
        return R.ok().put("text",sysTextDomain);
    }

    @RequestMapping("sys/user/text/add")
    public R addText(SysTextDomain sysTextDomain){
        log.debug("【 开始新增文章 】");
        userTextService.addText(sysTextDomain);
        log.debug("【 新增文章结束 】");
        return R.ok();
    }

    @RequestMapping("sys/user/text/update")
    public R updateText(SysTextDomain sysTextDomain){
        log.debug("【 开始修改文章 】");
        userTextService.updateText(sysTextDomain);
        log.debug("【 修改文章结束 】");
        return R.ok();
    }

    @RequestMapping("sys/user/text/delete")
    public R deleteText(String textId,String userId){
        log.debug("【 开始删除文章 】");
        userTextService.deleteText(textId,userId);
        log.debug("【 删除文章结束 】");
        return R.ok();
    }
}
